<?php

/**
 * Validator Class
 *
 * @author Newton
 */
class Validator {
    
    const QidError = '操作的题目似乎不存在 :(';
    const AidError = '操作的答案似乎不存在 :(';
    const NidError = '请确认要操作的公告是否存在 :(';
    const UidError = '用户信息不正确或不存在 :(';
    
    const LoginPlz = '请登录后继续操作';
    const UserTips = '你提交的题目将在管理员审核通过后出现在题目列表里';
    const RegTips = '您已经登录,如果确定需要再次注册请继续 :)';
    
    const AddSuccess = '公告发布成功!';
    const UpdateSuccess = '更新成功!';
    
    const PermissionDenied = '此处戒备森严,回头是岸,你可以叫你大哥管理员过来';
    
    const RetypePasswordWrong = "两次输入的密码不一致";
    const UserExists = "用户已经存在";
    const EmailExists = "邮箱已经注册";
    const UserOrPasswordWrong = "用户名或者密码错误";
    const PasswordWrong = "原密码错误";
    const NewPasswordWrong = "新密码和确认密码都不能为空";
    
    //分页条目值设定
    const QuesListPagesize = 2;
    const AnsListPagesize = 3;
    const UserListPagesize = 2;
    
    //uid 是否有效
    public function isUidValid($uid)
    {
        if(!isset($uid))
            return false;
        else
        {
            $userDb = new  Application_Model_DbTable_User();
            $user = $userDb->getUserById($uid);
            if(!isset($user))
                return false;
            return $user;
        }
    }
    
    //aid 是否有效
    public function isAidValid($aid)
    {
        if(!isset($aid))
            return FALSE;
        else
        {
            $answerDb = new Application_Model_DbTable_Answer();
            $answer = $answerDb->getAnswerById($aid);
            if(!isset($answer))
                return FALSE;
            
            return $answer;
        }
    }
    
    //qid 是否有效
    public function isQidValid($qid)
    {
        if(!isset($qid))
            return false;
        else
        {
            $questionDb = new  Application_Model_DbTable_Question();
            $question = $questionDb->getQuestionById($qid);
            if(!isset($question))
                return false;
            
            return $question;
        }
    }
    
    //nid 是否有效
    public function isNidValid($nid)
    {
        if(!isset($nid))
            return false;
        else
        {
            $noticeDb = new Application_Model_DbTable_Notice();
            $notice = $noticeDb->getNoticeById($nid);
            if(!isset($notice))
                return false;
            return $notice;
        }
    }
    
}

?>
